import random
money=random.randint(100,500)
print("你现在拥有",money,'元')
discount=random.randint(5,9)
print("恭喜你获得",discount,'折')
goodsinfo = [
    {'name': 'g1', 'price': 10},
    {'name': 'g2', 'price': 149},
    {'name': 'g3', 'price': 249}
]
staycar=[]
while True:
    ct=input("输入1继续购买")
    if int(ct)!=1:
        break

    target = input("输入要买的")
    selected_good = None
    for g in goodsinfo:
        if g['name'].lower() == target:
            selected_good = 'good'
            print("有这个商品")
            print('商品名:', g['name'], "价格：", g['price'], '元')
            break

    if selected_good is None:
        print("没有这个商品，请重新选择!")
        continue

    price=int(g['price'])
    dp=price*discount/10
    if  money-dp>0:
        money-=dp
        staycar.append(g['name'])
        print("经过优惠后你这个所购买的商品价格为：",dp,'元')
        print('本次消费：',dp,'您的余额还有',money,'元')

        eb=input("输入0将进行退货，退货后不能继续购买：")
        if int(eb)==0:
            if not staycar:
                print("购物车为空，不能退货")
            else:
                eg=input("请输入您要退款的商品：").lower()
                if eg in staycar:
                    for y in goodsinfo:
                        if eg==y['name']:
                            money=money+y['price']*10
                            staycar.remove(eg)
                            print('退货成功，现在购物车里有',staycar,'余额还有',money,'元')
                else:
                    print("您并没有买此商品，无法退货")

    else:
        print('余额不足以购买此商品')











